<template>
	<view class="me">
		<my-header bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">系统设置</block>
		</my-header>
        <view class="">
            <view class="cu-form-group margin-top">
				<view class="title">驾照类型</view>
				<picker @change="TagetDriver" :value="back_type" :range="driverType">
					<view class="picker">
						{{driver.model?driver.model:'请选择驾照类型'}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">考试科目</view>
				<picker @change="TagetExam" :value="driver.subject" :range="examType">
					<view class="picker">
						{{driver.subject?driver.subject:'请选择考试科目'}}
					</view>
				</picker>
			</view>
		</view>
		<view class="col">
            <view class="cu-btn round lg btn" @click="submit()">保存设置</view>
        </view>	
        {{content}}
        <rich-text :nodes="content"></rich-text>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
                driver:{},
				driverType:[
                    "c1","c2","a1","a2","b1","b2"
                ],
                examType:[
                    "科一","科四"
                ],
                content:""
			}
		}, 
		onLoad(){
            this.initData()
		},
		methods: {
			async initData(){
				const res=await uni.$request({
                },"api/driverExam/getUserInfo")
                res.data.driverInfo.subject=res.data.driverInfo.subject==1?"科一":"科四"
                this.driver=res.data.driverInfo
            },
            
			TagetDriver(e){
                const formData=this.driver
                formData.model=this.driverType[e.detail.value]
                this.driver=formData
            },
            TagetExam(e){
                const formData=this.driver
                formData.subject=this.examType[e.detail.value]
                this.driver=formData
                this.formData={
                    ...formData,
                    
                }
            },
            async submit(){
               const formData={
                   ...this.driver
                }
                console.log(formData);
                if (formData.subject) {
                    formData.subject=formData.subject=="科一"?1:4
                    const res=await uni.$request(formData,"/api/driverExam/SaveSetting")
                    if (res.code==200) {
                        uni.$err(res.msg,1)
                        
                    }else{
                        this.content=res
                    }
                }else{
                    uni.$err("请选择科目")
                }
            }
			
			
		}
	}
</script>

<style lang="scss">
    @import "./main";
    @import "../feedback/index"
</style>